package cn.kattomy.shop.order.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import cn.kattomy.shop.order.dao.OrderDao;
import cn.kattomy.shop.order.service.OrderService;
import cn.kattomy.shop.order.vo.Order;
import cn.kattomy.shop.order.vo.OrderItem;
import cn.kattomy.shop.user.vo.User;
import cn.kattomy.shop.utils.PageBean;

public class OrderServiceImpl implements OrderService {

	private OrderDao orderDao;
	
	public void setOrderDao(OrderDao orderDao) {
		this.orderDao = orderDao;
	}
	
	@Override
	public void save(Order order) {
		orderDao.save(order);
	}

	@Override
	public PageBean<Order> findByUid(Integer uid, Integer pageNo) {
//		设置当前页数以及每页显示的记录数
		Integer limit = 5;
		PageBean<Order> pageBean = new PageBean<Order>(pageNo, limit);
		//设置总记录数
		Integer totalItemNo = null;
		totalItemNo = orderDao.findByCountUid(uid);
		pageBean.setTotalItemNo(totalItemNo);
		//设置总页数？？？
		//设置每页显示的数据的集合
		Integer begin = (pageNo - 1) * limit;
		List<Order> list = orderDao.findByPageuid(uid, begin, limit);
		pageBean.setList(list);
		
		return pageBean;
	}

	@Override
	public Order findByOid(Integer oid) {
		
		return orderDao.findByOid(oid);
	}

	@Override
	public void update(Order currOrder) {
		orderDao.update(currOrder);
	}

	@Override
	public PageBean<Order> findByPageNo(Integer pageNo) {
		//设置当前页数以及每页显示的记录数
		Integer pageSize = 10;
		PageBean<Order> pageBean = new PageBean<>(pageNo, pageSize);
		//设置总记录数
		int totalItemNo = orderDao.findByCount();
		pageBean.setTotalItemNo(totalItemNo);
		//设置每页显示的数据的集合
		int begin = (pageNo - 1)* pageSize;
		List<Order> list = orderDao.findByPage(begin, pageSize);
		pageBean.setList(list);
		return pageBean;
	}

	@Override
	public List<OrderItem> findOrderItem(Integer oid) {
		return orderDao.findOrderItem(oid);
	}

	@Override
	public void delete(Order order) {
		orderDao.delete(order);
	}
}
